//-----------------------------------------------------------------------
// <copyright file="PublicationInfo.cs" company="iron9light">
//      Copyright (c) iron9light. All rights reserved.
// </copyright>
// <author>iron9light</author>
//-----------------------------------------------------------------------

namespace EventBrokerExtension
{
    using System;
    using System.Reflection;

    /// <summary>
    /// The publication info.
    /// </summary>
    public struct PublicationInfo : IEquatable<PublicationInfo>
    {
        private readonly string eventTopic;
        private readonly EventInfo targetEvent;

        /// <summary>
        /// Initializes a new instance of the <see cref="PublicationInfo"/> struct.
        /// </summary>
        /// <param name="eventTopic">Name of the event topic.</param>
        /// <param name="targetEvent">The target event.</param>
        public PublicationInfo(string eventTopic, EventInfo targetEvent)
        {
            this.eventTopic = eventTopic;
            this.targetEvent = targetEvent;
        }

        /// <summary>
        /// Gets the name of the event topic.
        /// </summary>
        /// <value>The name of the event topic.</value>
        public string EventTopic
        {
            get { return this.eventTopic; }
        }

        /// <summary>
        /// Gets the target event.
        /// </summary>
        /// <value>The target event.</value>
        public EventInfo TargetEvent
        {
            get { return this.targetEvent; }
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(PublicationInfo left, PublicationInfo right)
        {
            return left.Equals(right);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(PublicationInfo left, PublicationInfo right)
        {
            return !left.Equals(right);
        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return this.targetEvent.GetHashCode();
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (!(obj is PublicationInfo))
            {
                return false;
            }

            return this.Equals((PublicationInfo)obj);
        }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public bool Equals(PublicationInfo other)
        {
            return this.targetEvent == other.targetEvent && this.eventTopic == other.eventTopic;
        }
    }
}